package com.dengwei.smali.first.dwpull_to_refresh;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ListView;
import android.widget.Toast;

import com.dengwei.smali.first.dwpull_to_refresh.PullToRefresh.PullToDeafultHandler;
import com.dengwei.smali.first.dwpull_to_refresh.PullToRefresh.PullToRefreshFrameLayout;
import com.dengwei.smali.first.dwpull_to_refresh.PullToRefresh.PullToRefreshHandler;
import com.dengwei.smali.first.dwpull_to_refresh.PullToRefresh.TjPullToRefreshLayout;
import com.dengwei.smali.first.dwpull_to_refresh.adapter.Demo2Adapter;
import com.dengwei.smali.first.dwpull_to_refresh.adapter.DemoAdapter;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String[] data = new String[50];
        for (int i = 0; i < 50; i++) {
            data[i] = "item" + i;
        }
        RecyclerView listView = (RecyclerView) findViewById(R.id.listview);
//        ListView listView = (ListView) findViewById(R.id.listview);
        final TjPullToRefreshLayout refreshLayout = (TjPullToRefreshLayout) findViewById(R.id.pullToRefresh);
        listView.setLayoutManager(new LinearLayoutManager(this));

        refreshLayout.setHandler(new PullToDeafultHandler() {
            @Override
            public void onRefreshBegin(PullToRefreshFrameLayout frame) {
                Toast.makeText(MainActivity.this, "刷新成功", Toast.LENGTH_SHORT).show();
                refreshLayout.refreshComplete();
            }
        });

        refreshLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                refreshLayout.autoRefresh();
            }
        }, 1000);
//        listView.setAdapter(new Demo2Adapter(this, data));
//        listView.setAdapter(new Demo2Adapter(this, data));
        listView.setAdapter(new DemoAdapter(this, data));


    }
}
